<?php

namespace App\Providers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        if (config('app.env') === 'local') {
            DB::listen(function ($query) {
                $sql = array_reduce($query->bindings, function($sql, $binding) {
                    return preg_replace('/\?/', is_numeric($binding) ? $binding : sprintf("'%s'", $binding), $sql, 1);
                }, $query->sql);

                if(strpos($sql,'sys_operation_logs') === false){
                    Log::info($query->time.' ms --'.$sql);
                }
            });
        }
    }
}
